package com.cskaoyan.mall.commons.result;

import com.cskaoyan.mall.commons.constant.SysRetCodeConstants;

/**
 * @auther cskaoyan
 * @date 2022/8/16:20:21
 */
public class ServiceCallResponseUtil<T> {

    private ServiceCallResponse<T> serviceCallResponse;

    public ServiceCallResponseUtil() {
        serviceCallResponse = new ServiceCallResponse<>();
    }

    public ServiceCallResponse<T> ok(T t) {
        this.serviceCallResponse.setCallData(t);
        serviceCallResponse.setCode(SysRetCodeConstants.SERVICE_CALL_SUCCESS.getCode());
        serviceCallResponse.setMsg(SysRetCodeConstants.SERVICE_CALL_SUCCESS.getMessage());
        return serviceCallResponse;
    }

    public ServiceCallResponse fail(String msg) {
        serviceCallResponse.setCode(SysRetCodeConstants.SERVICE_CALL_SUCCESS.getCode());
        serviceCallResponse.setMsg(msg);
        if (msg == null || msg.isEmpty()) {
            serviceCallResponse.setMsg(SysRetCodeConstants.SERVICE_CALL_SUCCESS.getMessage());
        }

        return serviceCallResponse;
    }


}
